<?php
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
/**
 * An Enumeration for holding all the responses emitted by the social API.
 */
class response_error {
	/** value representing NOT IMPLEMENTED. */
	public static $NOT_IMPLEMENTED = 501;
	/** value representing UNAUTHORIZED. */
	public static $UNAUTHORIZED = 401;
	/** value representing FORBIDDEN. */
	public static $FORBIDDEN = 403;
	/** value representing BAD REQUEST. */
	public static $BAD_REQUEST = 400;
	/** value representing NOT FOUND. */
	public static $NOT_FOUND = 404;
	/** value representing INTERNAL SERVER ERROR. */
	public static $INTERNAL_ERROR = 500;
	/** value representing EXPECTATION FAILED. */
	public static $LIMIT_EXCEEDED = 509;
	
	/**
	 * The json value of the error.
	 */
	private $json_value;
	/**
	 * The http error code associated with the error.
	 */
	private $http_error_code;
	
	/**
	 * The HTTP response header
	 */
	private $http_error_msg;

	/**
	 * Construct a Response Error from the jsonValue as a string and the Http Error Code.
	 * @param jsonValue the json String representation of the error code.
	 * @param httpErrorCode the numeric HTTP error code.
	 */
	public function __construct($json_value) {
		$this->json_value = $json_value;
		switch ($this->json_value) {
			case self::$BAD_REQUEST:
				$this->http_error_msg = '400 Bad Request';
				$this->http_error_code = 400;
				break;
			case self::$UNAUTHORIZED:
				$this->http_error_msg = '401 Unauthorized';
				$this->http_error_code = 401;
				break;
			case self::$FORBIDDEN:
				$this->http_error_msg = '403 Forbidden';
				$this->http_error_code = 403;
				break;
			case self::$FORBIDDEN:
				$this->http_error_msg = '404 Not Found';
				$this->http_error_code = 404;
				break;
			case self::$NOT_IMPLEMENTED:
				$this->http_error_msg = '501 Not Implemented';
				$this->http_error_code = 501;
				break;
			case self::$LIMIT_EXCEEDED:
				//FIXME or should this be a 507 Insufficient Storage (WebDAV, RFC 4918) ?
				$this->http_error_msg = '509 Limit Exceeeded';
				$this->http_error_code = 509;
				break;
			case self::$INTERNAL_ERROR:
			default:
				$this->http_error_msg = '500 Internal Server Error';
				$this->http_error_code = 500;
				break;
		}
	}

	/**
	 *
	 * Converts the ResponseError to a String representation
	 */
	public function __toString() {
		return $this->json_value;
	}

	/**
	 * Get the HTTP error code.
	 * @return the Http Error code.
	 */
	public function get_http_error_code() {
		return $this->http_error_code;
	}
	
	/**
	 * Get the HTTP error response header.
	 * @return the Http response header.
	 */
	public function get_http_error_msg() {
		return $this->http_error_msg;
	}
}
